package com.s59.rbac.controller;

import com.s59.rbac.common.R;
import com.s59.rbac.common.RequiredPerms;
import com.s59.rbac.entity.Role;
import com.s59.rbac.service.IRoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2023-05-15
 */
@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private IRoleService roleService;

//    @RequiredPerms("role:add")
    @RequiresPermissions("role:add")
    @PostMapping
    public R add(@RequestBody Role role){
        roleService.save(role);
        return R.ok();
    }

//    @RequiredPerms("role:delete")
    @RequiresPermissions("manager")
    @DeleteMapping("/{roleId}")
    public R del(@PathVariable  Long roleId){
        roleService.removeById(roleId);
        return R.ok();
    }

//    @RequiredPerms("role:update")
    @RequiresPermissions("role:update")
    @PutMapping
    public R update(@RequestBody Role role){
        roleService.saveOrUpdate(role);
        return R.ok();
    }

//    @RequiredPerms("role:list")
    @RequiresPermissions("role:list")
    @GetMapping
    public R getAll(){
        List<Role> list = roleService.list();
        return R.ok(list);
    }



}
